*************************************************************************************************************
*									 Reproduction do-file for 												*
*										Steiner, Nils D.    		   										*
*						Generational Change in Party Support in Germany										*
* The Decline of the Volksparteien, the Rise of the Greens, and the Transformation of the Education Divide	*
*************************************************************************************************************

* This do file reproduces all results reported in the paper and the appendix

* How to reproduce the results: 
* 1. Run the code below on the reproduction dataset 
* Note: First part of the code below (commented out) makes transparent how the reproduction dataset was produced


******************************** Settings **************************************
* install ados and packages used (if necessary)
ssc install fre
ssc install estout
ssc install mplotoffset
ssc install schemepack

	* install fitstat ado
		* search spost13_ado
		net from https://jslsoc.sitehost.iu.edu/stata/		
		net install spost13_ado, replace

* settings
clear all
version 17.0
set scheme white_tableau
graph set window fontface "Times New Roman"


/*
***************************************************************************************************************************
******************************************** CONSTRUCTION OF DATASET ******************************************************
***************************************************************************************************************************

* set working directory 
	capture cd "C:\Users\steinern\OneDrive\APC Germany\Data"
	capture cd "C:\Users\NilsS\OneDrive\APC Germany\Data"

* open the Gethin et al. data for Germany
	* includes post-election surveys from 1949 to 2017
	use "de.dta" 

* add GLES post-election cross-section for 2021, version 1.0.0
	* dataset already prepared for appending 
	append using "Datensatz_2021_Gles rekodiert.dta"

* replace the 1961 data with a recoded version of the original dataset (that includes proper information on non-voting)
	drop if year==1961
	append using "1961_Nachwahlquerschnitt.dta"

		* Check variables over time
		bysort year: fre vote 

		bysort year: fre turnout // "did not vote" not available in 1961
		bysort year: fre votecducsu 
		bysort year: fre votespd 
		bysort year: fre votefdp 
		bysort year: fre votegruene 
		bysort year: fre votelinke

		bysort year: fre inc
		bysort year: fre educ

* variable collapsed_vote: 0=Others, 1=CDU/CSU, 2=SPD, 3=FDP, 4=Grüne, 5=Linke, 6, AfD, 7=abstention
	gen collapsed_vote=vote
	replace collapsed_vote=0 if vote!=. & vote!=.a & vote!=.b & vote!=.k & vote!=.n & vote!=.t & vote!=.v & vote!=.w
	replace collapsed_vote=1 if vote==1 // Union
	replace collapsed_vote=2 if vote==2 // SPD
	replace collapsed_vote=3 if vote==3 // FDP
	replace collapsed_vote=4 if vote==18 | vote==21 //GRUENE
	replace collapsed_vote=5 if vote==27 | vote==19 //LINKE
	replace collapsed_vote=6 if vote==15 // AfD
	replace collapsed_vote=7 if vote==99 // abstention

* merge the dataset with a dataset containing a weight per year region and vote choice (to adjust to official election results)   
	sort year collapsed_vote
	merge m:1 year region collapsed_vote using "Weights_Voteshare.dta"

	rename weightvoteshare_reg_wregionalwei weightvoteshare_reg_wregionalw 

* check weights
	bysort year region: sum weight_voteshare_reg
		// always about 1 as it should be
	
	svyset _n, weight(weightvoteshare) vce(linearized) singleunit(missing)

	foreach year of numlist 1949 1953 1957 1961 1965 1969 1972 1976 1980 1983 1987 1990 1994 1998 2002 2005 2009 2013 2017 2021 {
	svy: tab collapsed_vote if year==`year'
	}

* define the data a survey dataset with weight
svyset _n, weight(weightvoteshare_reg_wregionalw) vce(linearized) singleunit(missing)

		
**** RECODING OF VARIABLES

* birth year
	gen yrbrn=year-age

	
* cohorts
	* basic scheme
	gen cohort=0 if yrbrn<=1900
	replace cohort=1 if yrbrn>=1901 & yrbrn<=1927
	replace cohort=2 if yrbrn>=1928 & yrbrn<=1945
	replace cohort=3 if yrbrn>=1946 & yrbrn<=1964
	replace cohort=4 if yrbrn>=1965 & yrbrn<=1979
	replace cohort=5 if yrbrn>=1980 & yrbrn<. 

	label variable cohort "birth cohort"

	label define cohorts 0 "-1900" 1 "01-27" 2 "28-45" 3 "46-64" 4 "65-79" 5 "80-"
	label values cohort cohorts

	* collapsing lost generation & WW II generation 
	gen cohort2=0 if yrbrn<=1927
	replace cohort2=1 if yrbrn>=1928 & yrbrn<=1945
	replace cohort2=2 if yrbrn>=1946 & yrbrn<=1964
	replace cohort2=3 if yrbrn>=1965 & yrbrn<=1979
	replace cohort2=4 if yrbrn>=1980 & yrbrn<. 

	label variable cohort2 "birth cohort"

	label define cohorts2 0 "-1927" 1 "28-45" 2 "46-64" 3 "65-79" 4 "80-"
	label values cohort2 cohorts2

	* collapsing lost generation & WW II generation & silent generation 
	gen cohort3=0 if yrbrn<=1945
	replace cohort3=1 if yrbrn>=1946 & yrbrn<=1964
	replace cohort3=2 if yrbrn>=1965 & yrbrn<=1979
	replace cohort3=3 if yrbrn>=1980 & yrbrn<. 

	label variable cohort3 "birth cohort"

	label define cohorts3 0 "-1945" 1 "46-64" 2 "65-79" 3 "80-"
	label values cohort3 cohorts3
		
	* fine-grained cohorts (birth decade)
	gen cohort_dec=0 if yrbrn<=1919 
	replace cohort_dec=1 if yrbrn>=1920 & yrbrn<=1929
	replace cohort_dec=2 if yrbrn>=1930 & yrbrn<=1939
	replace cohort_dec=3 if yrbrn>=1940 & yrbrn<=1949
	replace cohort_dec=4 if yrbrn>=1950 & yrbrn<=1959
	replace cohort_dec=5 if yrbrn>=1960 & yrbrn<=1969
	replace cohort_dec=6 if yrbrn>=1970 & yrbrn<=1979
	replace cohort_dec=7 if yrbrn>=1980 & yrbrn<=1989
	replace cohort_dec=8 if yrbrn>=1990 & yrbrn<.
	
	label variable cohort_dec "birth cohort"

	label define cohorts_dec 0 "-1919" 1 "1920s" 2 "1930s" 3 "1940s" 4 "1950s" 5 "1960s" 6 "1970s" 7 "1980s" 8 "1990s-" 
	label values cohort_dec cohorts_dec

	tab cohort_dec

	* fine-grained cohorts (birth decade) for East
	gen cohort_dec2=0 if yrbrn<=1939 
	replace cohort_dec2=1 if yrbrn>=1940 & yrbrn<=1949
	replace cohort_dec2=2 if yrbrn>=1950 & yrbrn<=1959
	replace cohort_dec2=3 if yrbrn>=1960 & yrbrn<=1969
	replace cohort_dec2=4 if yrbrn>=1970 & yrbrn<=1979
	replace cohort_dec2=5 if yrbrn>=1980 & yrbrn<=1989
	replace cohort_dec2=6 if yrbrn>=1990 & yrbrn<.
	
	label variable cohort_dec2 "birth cohort"

	label define cohorts_dec2 0 "-1939" 1 "1940s" 2 "1950s" 3 "1960s" 4 "1970s" 5 "1980s" 6 "1990s-" 
	label values cohort_dec2 cohorts_dec2

	
* age groups (coded as in: van der Brug & Rekker 2021: 722)
	gen age_group=0 if age<=21
	replace age_group=1 if age>=22 & age<=29
	replace age_group=2 if age>=30 & age<=65
	replace age_group=3 if age>=66 & age<.

	label variable age_group "age group"

	label define age_group 0 "-21" 1 "22-29" 2 "30-65" 3 "66-"  
	label values age_group age_group


	* alternative age groups (finer)
	gen age_group2=0 if age<=24
	replace age_group2=1 if age>=25 & age<=39
	replace age_group2=2 if age>=40 & age<=54
	replace age_group2=3 if age>=55 & age<=69
	replace age_group2=4 if age>=70 & age<.

	label variable age_group2 "age group"

	label define age_group2 0 "-24" 1 "25-39" 2 "40-54" 3 "55-69" 4 "70-" 
	label values age_group2 age_group2	

* year
	label variable year "election year"

	label define year 1949 "49" 1953 "53" 1957 "57" 1961 "61" 1965 "65" 1969 "69" 1972 "72" 1976 "76" 1980 "80" 1983 "83" 1987 "87" 1990 "90" 1994 "94" 1998 "98" 2002 "02" 2005 "05" 2009 "09" 2013 "13" 2017 "17" 2021 "21"
	label values year year

	label define year_long 1949 "1949" 1953 "1953" 1957 "1957" 1961 "1961" 1965 "1965" 1969 "1969" 1972 "1972" 1976 "1976" 1980 "1980" 1983 "1983" 1987 "1987" 1990 "1990" 1994 "1994" 1998 "1998" 2002 "2002" 2005 "2005" 2009 "2009" 2013 "2013" 2017 "2017" 2021 "2021"

	
* region
	recode region (1=0 "West") (2=1 "East"), gen(East)
		tab region East

		
* high education: dummy variable dinstinguishing between at (Fach-)Abitur or not 
	fre educ if year==1961
	recode educ (1 2=0) (3 4=1), gen(educ_high)
	label variable educ_high "high education"

	tab educ educ_high

	* correct values for 1998 using the original education variable (there is a coding error in Gethin et al. for this year)
	replace educ_high=0 if year==1998 & educ2>=1 & educ2<=4
	replace educ_high=1 if year==1998 & educ2>=5 & educ2<=9
	
	
* Compute a weight ADJUSTING FOR DIFFERENT SAMPLE SIZES OVER TIME		
	gen one=1
	bysort year: egen samplesize=sum(one)
	tab samplesize
	gen weight_samplesizeadj=1000/samplesize
	tab weight_samplesizeadj

		bysort year: egen checksum=sum(weight_samplesizeadj)
		bysort year: sum checksum


*** save dataset
save "Steiner_Generational Change_Reproduction.dta", replace
	
*/


**# Bookmark #1	
***************************************************************************************************************************
******************************************** DESCRIPTIVE RESULTS **********************************************************
***************************************************************************************************************************
use "Steiner_Generational Change_Reproduction.dta"


***** Descriptive stuff

*** Appendix A: Additional information on the cohort and age group classifications
	
	* Compare overlap between age group and cohort
		* Table A1: Cross-tabulation of cohorts and age groups (all data)
		tab cohort age_group 
		
		* Table A2: Cross-tabulation of cohorts and age groups (data from 1980 onwards)
		tab cohort age_group if year>=1980
		
	* Show cohort composition across years	
		* Figure A1: Cohort distribution in percent by election year 
		gen weightvotesh_reg_wregionalw_mult=weightvoteshare_reg_wregionalw*10000000000000000000000000000000000
		label values year year_long	
		
		hist cohort [fweight=weightvotesh_reg_wregionalw_mult], by(year, legend(off) note(" ", size(zero)) scale(*1.6) row(5)) discrete percent ///
			xlabel(0 (1) 5, valuelabel angle(090)) addlabels addlabopts(mlabformat(%9.0f) mlabsize(vsmall)) xtitle(" ", size(zero)) ytitle(" ", size(zero)) ysize(6) ///
			name(FigureA1, replace)

			
***	Appendix B: Levels of education across cohorts
	
	* Tertiary education over time and across cohorts 
	label values year year	
		
	svy: tab year educ_high, row
	svy: tab cohort educ_high, row
	
	* Figure B1: Share with high education across cohorts
	preserve
	collapse educ_high [pweight=weightvoteshare_reg_wregionalw], by(cohort)
	label values cohort cohorts
	twoway (connected educ_high cohort, legend(size(small)) sort xlabel( , valuelabel) ytitle("share with high education") ylabel(0 (0.1) 0.6) scale(*1.2)), name(FigureB1, replace)
	restore 
	
	* Figure B2: Share with high education across cohorts and years
	preserve
	collapse educ_high [pweight=weightvoteshare_reg_wregionalw], by(year cohort)
	label values year year_long	
	twoway (connected educ_high cohort, legend(size(small)) sort xlabel( 0/5, valuelabel angle(090)) ytitle("share with high education") ylabel(0 (0.1) 0.7, gmin gmax) by(year, note(" ") row(5)) ysize(7)), name(FigureB2, replace)
	restore 
	
	
	
**# Bookmark #2	
***************************************************************************************************************************
*************************** BASIC APC MODELS (WITHOUT EDUCATION INTERACTION, INCL. EASTERN GERMANY) ***********************
***************************************************************************************************************************

	* Regression models	
	* CDU/CSU
	logit votecducsu ib3.cohort##i.East i.year i.age_group i.sex if turnout==1 [pweight=weightvoteshare_reg_wregionalw]
		estadd fitstat
		eststo UNION_base
		
	* SPD 
	logit votespd ib3.cohort##i.East i.year i.age_group i.sex if turnout==1 [pweight=weightvoteshare_reg_wregionalw]
		estadd fitstat
		eststo SPD_base	
	
	* FDP
	logit votefdp ib3.cohort##i.East i.year i.age_group i.sex if turnout==1 [pweight=weightvoteshare_reg_wregionalw]
		estadd fitstat
		eststo FDP_base
		
	* GREENS
	logit votegruene ib2.cohort2##i.East i.year i.age_group i.sex if year>=1980 & turnout==1 [pweight=weightvoteshare_reg_wregionalw]
		estadd fitstat
		eststo GREENS_base	

	* PDS/LEFT
	logit votelinke ib2.cohort2##i.East i.year i.age_group i.sex if year>=1994 & turnout==1 [pweight=weightvoteshare_reg_wregionalw]
		estadd fitstat
		eststo LEFT_base	

	* AfD
	logit voteafd ib1.cohort3##i.East i.year i.sex if year>=2013 & turnout==1 [pweight=weightvoteshare_reg_wregionalw]
		estadd fitstat
		eststo AfD_base
	
	
	* Figure 2: Predicted probability of party choice by cohorts and West vs. East
	estimates restore UNION_base
	margins, at(cohort=(0/5) East=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) ///  
		legend(off) text(0.24 2 "East", color(orange)) text(0.52 2 "West", color(ebblue)) ///
		title(CDU/CSU) name(UNION_base_coh, replace) nodraw
		
	estimates restore SPD_base
	margins, at(cohort=(0/5) East=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) ///  
		legend(off) title(SPD) name(SPD_base_coh, replace) nodraw
			
	estimates restore FDP_base
	margins, at(cohort=(0/5) East=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) ///  
		legend(off) title(FDP) name(FDP_base_coh, replace) nodraw
			
	estimates restore GREENS_base
	margins, at(cohort2=(0/4) East=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) ///  
		legend(off) title(Greens) name(GREENS_base_coh, replace) nodraw
		
	estimates restore LEFT_base
	margins, at(cohort2=(0/4) East=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) ///  
		legend(off) title(PDS/LEFT) name(LEFT_base_coh, replace) nodraw
		
	estimates restore AfD_base
	margins, at(cohort3=(0/3) East=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) /// 
		legend(off) title(AfD) name(AfD_base_coh, replace) nodraw	
	
	* Combine to Figure 2 
	graph combine UNION_base_coh SPD_base_coh FDP_base_coh GREENS_base_coh LEFT_base_coh AfD_base_coh, row(3) imargin(tiny) xsize(4) iscale(*1.2) name(Figure2, replace) 
		graph export "Figure2.pdf", replace

		
	*** Appendix C: Further results for Figure 2 (baseline APC model)
		
	* Table C1: Regression table for results in Figure 2
	esttab UNION_base SPD_base FDP_base GREENS_base LEFT_base AfD_base using "TableC1.rtf", b(a2) se(a2) star(+ 0.10 * 0.05 ** 0.01 *** 0.001) scalars(r2_mz) ///
		label nogaps  ///
		drop(0.East 0.cohort#0.East 1.cohort#0.East 2.cohort#0.East 3.cohort#0.East 1949.year 4.cohort#0.East ///
		1949.year 0.age_group 0.cohort2#0.East 1.cohort2#0.East 2.cohort2#0.East 3.cohort2#0.East 0.sex) ///
		replace
		
		
		* Figure C1: Predicted probabilities by cohort, age, and election year from regressions in Table C1
		global ylabel "ylabel(.0 (.1) .5, gmin gmax)"
		label values year year	
	
		* CDU/CSU
		estimates restore UNION_base

			* cohort effect
			margins, at(cohort=(0/5) East=(0 1))
			mplotoffset, level(85) ytitle(" ") $ylabel ///  
				xlabel( , angle(045)) ///
				legend(off) text(0.23 2 "East", color(orange)) text(0.54 2 "West", color(ebblue)) title(" ", size(zero)) name(UNION_base_coh, replace)	nodraw			
		
			* age effect
			margins, at(age_group=(0/3))
			mplotoffset, level(85) ytitle(" ") title(" ", size(zero)) $ylabel /// 
				xlabel( , angle(045)) ///
				name(UNION_base_age, replace) nodraw	

			* period effect
			margins, at(year=(1949 1953 1957 1961 1965 1969 1972 1976 1980 1983 1987 1990 1994 1998 2002 2005 2009 2013 2017 2021))
			mplotoffset, level(85) ytitle(" ") title(" ", size(zero)) scale(*0.9) $ylabel ///
				name(UNION_base_year, replace) nodraw

			* combine graphs
			graph combine UNION_base_coh UNION_base_age, row(1) imargin(zero) iscale(*1.2) name(UNION_base_all, replace) nodraw

			graph combine UNION_base_all UNION_base_year, row(2) title(CDU/CSU, size(small)) imargin(zero) name(UNION_base_all, replace) nodraw

		* SPD 
		estimates restore SPD_base
		
			* cohort effect
			margins, at(cohort=(0/5) East=(0 1))
			mplotoffset, level(85) ytitle(" ") $ylabel ///  
				xlabel( , angle(045)) ///
				legend(off) title(" ", size(zero)) name(SPD_base_coh, replace) nodraw
		
			* age effect
			margins, at(age_group=(0/3))
			mplotoffset, level(85) ytitle(" ") title(" ", size(zero)) $ylabel ///  
				xlabel( , angle(045)) ///
				name(SPD_base_age, replace) nodraw

			* period effect
			margins, at(year=(1949 1953 1957 1961 1965 1969 1972 1976 1980 1983 1987 1990 1994 1998 2002 2005 2009 2013 2017 2021))
			mplotoffset, level(85) ytitle(" ") title(" ", size(zero)) ylabel(.2 (.1) .5) scale(*0.9) $ylabel ///
				name(SPD_base_year, replace) nodraw

			* combine graphs
			graph combine SPD_base_coh SPD_base_age, row(1) imargin(zero) ycommon iscale(*1.2) name(SPD_base_all, replace) nodraw

			graph combine SPD_base_all SPD_base_year, row(2) title(SPD, size(small)) imargin(zero) ycommon name(SPD_base_all, replace) nodraw
		
		global ylabel "ylabel(.0 (.05) .15, gmin gmax)"
			
		* FDP
		estimates restore FDP_base

			* cohort effect
			margins, at(cohort=(0/5) East=(0 1))
			mplotoffset, level(85) ytitle(" ") title(" ", size(zero)) $ylabel ///  
				xlabel( , angle(045)) ///
				legend(off) name(FDP_base_coh, replace) nodraw

			* age effect
			margins, at(age_group=(0/3))
			mplotoffset, level(85) ytitle(" ") title(" ", size(zero)) $ylabel ///  
				xlabel( , angle(045)) ///
				name(FDP_base_age, replace) nodraw

			* period effect
			margins, at(year=(1980 1983 1987 1990 1994 1998 2002 2005 2009 2013 2017 2021))
			mplotoffset, level(85) ytitle(" ") title(" ", size(zero)) scale(*0.9) $ylabel ///  
				name(FDP_base_year, replace) nodraw

			* combine graphs
			graph combine FDP_base_coh FDP_base_age, row(1) imargin(zero) ycommon iscale(*1.2) name(FDP_base_all, replace) nodraw

			graph combine FDP_base_all FDP_base_year, row(2) title(FDP, size(small)) imargin(zero) ycommon name(FDP_base_all, replace) nodraw						
			
		* GREENS
		estimates restore GREENS_base

			* cohort effect
			margins, at(cohort2=(0/4) East=(0 1))
			mplotoffset, level(85) ytitle(" ") title(" ", size(zero)) $ylabel ///  
				xlabel( , angle(045)) ///
				legend(off) name(GREENS_base_coh, replace) nodraw

			* age effect
			margins, at(age_group=(0/3))
			mplotoffset, level(85) ytitle(" ") title(" ", size(zero)) $ylabel ///  
				xlabel( , angle(045)) ///
				name(GREENS_base_age, replace) nodraw

			* period effect
			margins, at(year=(1980 1983 1987 1990 1994 1998 2002 2005 2009 2013 2017 2021))
			mplotoffset, level(85) ytitle(" ") title(" ", size(zero)) scale(*0.9) $ylabel ///  
				name(GREENS_base_year, replace) nodraw

			* combine graphs
			graph combine GREENS_base_coh GREENS_base_age, row(1) imargin(zero) ycommon iscale(*1.2) name(GREENS_base_all, replace) nodraw

			graph combine GREENS_base_all GREENS_base_year, row(2) title(Greens, size(small)) imargin(zero) ycommon name(GREENS_base_all, replace) nodraw
						
		global ylabel "ylabel(.0 (.1) .3, gmin gmax)"

		* LINKE
		estimates restore LEFT_base

			* cohort effect
			margins, at(cohort2=(0/4) East=(0 1))
			mplotoffset, level(85) ytitle(" ") title(" ", size(zero)) $ylabel ///  
				xlabel( , angle(045)) ///
				legend(off) name(LEFT_base_coh, replace) nodraw

			* age effect
			margins, at(age_group=(0/3))
			mplotoffset, level(85) ytitle(" ") title(" ", size(zero)) $ylabel ///  
				xlabel( , angle(045)) ///
				name(LEFT_base_age, replace) nodraw

			* period effect
			margins, at(year=(1994 1998 2002 2005 2009 2013 2017 2021))
			mplotoffset, level(85) ytitle(" ") title(" ", size(zero)) scale(*0.9) $ylabel ///  
				name(LEFT_base_year, replace) nodraw

			* combine graphs
			graph combine LEFT_base_coh LEFT_base_age, row(1) imargin(zero) ycommon iscale(*1.2) name(LEFT_base_all, replace) nodraw

			graph combine LEFT_base_all LEFT_base_year, row(2) title(PDS/LEFT, size(small)) imargin(zero) ycommon name(LEFT_base_all, replace) nodraw
			
		* AfD (omit age group)
		estimates restore AfD_base

			* cohort effect
			margins, at(cohort3=(0/3) East=(0 1))
			mplotoffset, level(85) ytitle(" ") title(" ", size(zero)) $ylabel /// 
				legend(off) scale(*0.9) name(AfD_base_coh, replace) nodraw
			
			* period effect
			margins, at(year=(2013 2017 2021))
			mplotoffset, level(85) ytitle(" ") title(" ", size(zero)) scale(*0.9) $ylabel ///  
				name(AfD_base_year, replace) nodraw

			* combine graphs
			graph combine AfD_base_coh AfD_base_year, row(2) title(AfD, size(small)) imargin(zero) ycommon name(AfD_base_all, replace) nodraw
			
		*** Combine graph for main parties with cohort, period and age patterns
			graph combine UNION_base_all SPD_base_all FDP_base_all GREENS_base_all LEFT_base_all AfD_base_all, row(2) imargin(tiny) xsize(7.5) iscale(*1.5) name(FigureC1, replace)
		
		
		
**# Bookmark #3	
***************************************************************************************************************************
******************** Appendix D: Results from robustness checks for Figure 2 (baseline APC model) *************************
***************************************************************************************************************************
		
	***** Figure D1: Predicted probability of party choice by cohorts and West vs. East (without weight)
	* Regression models	
	* CDU/CSU
	logit votecducsu ib3.cohort##i.East i.year i.age_group i.sex if turnout==1 
		estadd fitstat
		eststo UNION_base
		
	* SPD 
	logit votespd ib3.cohort##i.East i.year i.age_group i.sex if turnout==1 
		estadd fitstat
		eststo SPD_base	
	
	* FDP
	logit votefdp ib3.cohort##i.East i.year i.age_group i.sex if turnout==1 
		estadd fitstat
		eststo FDP_base
		
	* GREENS
	logit votegruene ib2.cohort2##i.East i.year i.age_group i.sex if year>=1980 & turnout==1 
		estadd fitstat
		eststo GREENS_base	

	* PDS/LEFT
	logit votelinke ib2.cohort2##i.East i.year i.age_group i.sex if year>=1994 & turnout==1 
		estadd fitstat
		eststo LEFT_base	

	* AfD
	logit voteafd ib1.cohort3##i.East i.year i.sex if year>=2013 & turnout==1 
		estadd fitstat
		eststo AfD_base	
						 	
	* Predicted probabilities by cohort
	global ylabel "ylabel(.0 (.1) .5, gmin gmax)"
		
	estimates restore UNION_base
	margins, at(cohort=(0/5) East=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) ///  
		legend(off) text(0.24 2 "East", color(orange)) text(0.48 2 "West", color(ebblue)) title(CDU/CSU) name(UNION_base_coh, replace) nodraw	
	
	estimates restore SPD_base
	margins, at(cohort=(0/5) East=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) ///  
		legend(off) title(SPD) name(SPD_base_coh, replace) nodraw
		
	global ylabel "ylabel(.0 (.05) .25, gmin gmax)"
		
	estimates restore FDP_base
	margins, at(cohort=(0/5) East=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) ///  
		legend(off) title(FDP) name(FDP_base_coh, replace) nodraw
			
	estimates restore GREENS_base
	margins, at(cohort2=(0/4) East=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) ///  
		legend(off) title(GREENS) name(GREENS_base_coh, replace) nodraw

	estimates restore LEFT_base
	margins, at(cohort2=(0/4) East=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) ///  
		legend(off) title(PDS/LEFT) name(LEFT_base_coh, replace) nodraw
		
	estimates restore AfD_base
	margins, at(cohort3=(0/3) East=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) /// 
		legend(off) title(AfD) name(AfD_base_coh, replace) nodraw	
	
	* Combine figure for main parties with only cohort patterns
	graph combine UNION_base_coh SPD_base_coh FDP_base_coh GREENS_base_coh LEFT_base_coh AfD_base_coh, row(3) imargin(tiny) xsize(4) iscale(*1.2) name(FigureD1, replace) 
	
	
	
	***** Figure D2: Predicted probability of party choice by cohorts and West vs. East (fine-grained cohorts)
	* Regression models	
	* CDU/CSU
	logit votecducsu ib3.cohort_dec##i.East i.year i.age_group i.sex if turnout==1 [pweight=weightvoteshare_reg_wregionalw]
		estadd fitstat
		eststo UNION_base_finecoh
	
	* SPD 
	logit votespd ib3.cohort_dec##i.East i.year i.age_group i.sex if turnout==1 [pweight=weightvoteshare_reg_wregionalw]
		estadd fitstat
		eststo SPD_base_finecoh		
	
	* FDP
	logit votefdp ib3.cohort_dec##i.East i.year i.age_group i.sex if turnout==1 [pweight=weightvoteshare_reg_wregionalw]
		estadd fitstat
		eststo FDP_base_finecoh	
	
	* GREENS
	logit votegruene ib2.cohort_dec##i.East i.year i.age_group i.sex if year>=1980 & turnout==1 [pweight=weightvoteshare_reg_wregionalw]
		estadd fitstat
		eststo GREENS_base_finecoh		
	
	* PDS/LEFT
	logit votelinke ib2.cohort_dec##i.East i.year i.age_group i.sex if year>=1994 & turnout==1 [pweight=weightvoteshare_reg_wregionalw]
		estadd fitstat
		eststo LEFT_base_finecoh	
		
	* AfD
	logit voteafd ib1.cohort_dec##i.East i.year i.sex if year>=2013 & turnout==1 [pweight=weightvoteshare_reg_wregionalw]
		estadd fitstat
		eststo AfD_base_finecoh			
		
		
	* Predicted probabilities by cohort
	global ylabel "ylabel(.0 (.1) .6, gmin gmax)"
		
	estimates restore UNION_base_finecoh
	margins, at(cohort_dec=(0/8) East=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) xlabel( , angle(90)) ///  
		legend(off) text(0.22 4 "East", color(orange)) text(0.46 4 "West", color(ebblue)) title(CDU/CSU) name(UNION_base_finecoh, replace) nodraw	
	
	global ylabel "ylabel(.0 (.1) .5, gmin gmax)"

	estimates restore SPD_base_finecoh
	margins, at(cohort_dec=(0/8) East=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) xlabel( , angle(90)) ///  
		legend(off) title(SPD) name(SPD_base_finecoh, replace) nodraw	

	global ylabel "ylabel(.0 (.05) .15, gmin gmax)"
	
	estimates restore FDP_base_finecoh
	margins, at(cohort_dec=(0/8) East=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) xlabel( , angle(90)) ///  
		legend(off) title(FDP) name(FDP_base_finecoh, replace) nodraw	

	global ylabel "ylabel(.0 (.05) .2, gmin gmax)"
	
	estimates restore GREENS_base_finecoh
	margins, at(cohort_dec=(0/8) East=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) xlabel( , angle(90)) ///  
		legend(off) title(GREENS) name(GREENS_base_finecoh, replace) nodraw 

	global ylabel "ylabel(.0 (.1) .3, gmin gmax)"
	
	estimates restore LEFT_base_finecoh
	margins, at(cohort_dec=(0/8) East=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) xlabel( , angle(90)) ///  
		legend(off) title(PDS/LEFT) name(LEFT_base_finecoh, replace) nodraw

	global ylabel "ylabel(.0 (.05) .25, gmin gmax)"

	estimates restore AfD_base_finecoh	
	margins, at(cohort_dec=(0/8) East=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) xlabel( , angle(90)) /// 
		legend(off) title(AfD) name(AfD_base_finecoh, replace) nodraw					 		
	
	* Combine figure for main parties with only cohort patterns
	graph combine UNION_base_finecoh SPD_base_finecoh FDP_base_finecoh GREENS_base_finecoh LEFT_base_finecoh AfD_base_finecoh, row(3) imargin(tiny) xsize(4) iscale(*1.2) name(FigureD2, replace)			
	
	
	
	***** Figure D3: Predicted probability of party choice by cohorts and West vs. East (fine-grained age groups)
	* Regression models	
	* CDU/CSU
	logit votecducsu ib3.cohort##i.East i.year i.age_group2 i.sex if turnout==1 [pweight=weightvoteshare_reg_wregionalw]
		estadd fitstat
		eststo UNION_base
		
	* SPD 
	logit votespd ib3.cohort##i.East i.year i.age_group2 i.sex if turnout==1 [pweight=weightvoteshare_reg_wregionalw]
		estadd fitstat
		eststo SPD_base	
	
	* FDP
	logit votefdp ib3.cohort##i.East i.year i.age_group2 i.sex if turnout==1 [pweight=weightvoteshare_reg_wregionalw]
		estadd fitstat
		eststo FDP_base
		
	* GREENS
	logit votegruene ib2.cohort2##i.East i.year i.age_group2 i.sex if year>=1980 & turnout==1 [pweight=weightvoteshare_reg_wregionalw]
		estadd fitstat
		eststo GREENS_base	

	* PDS/LEFT
	logit votelinke ib2.cohort2##i.East i.year i.age_group2 i.sex if year>=1994 & turnout==1 [pweight=weightvoteshare_reg_wregionalw]
		estadd fitstat
		eststo LEFT_base	

	* AfD
	logit voteafd ib1.cohort3##i.East i.year i.sex if year>=2013 & turnout==1 [pweight=weightvoteshare_reg_wregionalw]
		estadd fitstat
		eststo AfD_base	
						 	
	* Predicted probabilities by cohort
	global ylabel "ylabel(.0 (.1) .5, gmin gmax)"
		
	estimates restore UNION_base
	margins, at(cohort=(0/5) East=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) ///  
		legend(off) text(0.24 2 "East", color(orange)) text(0.52 2 "West", color(ebblue)) title(CDU/CSU) name(UNION_base_coh, replace) nodraw
			
	estimates restore SPD_base
	margins, at(cohort=(0/5) East=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) ///  
		legend(off) title(SPD) name(SPD_base_coh, replace) nodraw
		
	global ylabel "ylabel(.0 (.05) .2, gmin gmax)"
		
	estimates restore FDP_base
	margins, at(cohort=(0/5) East=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) ///  
		legend(off) title(FDP) name(FDP_base_coh, replace) nodraw
			
	estimates restore GREENS_base
	margins, at(cohort2=(0/4) East=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) ///  
		legend(off) title(GREENS) name(GREENS_base_coh, replace) nodraw

	global ylabel "ylabel(.0 (.05) .35, gmin gmax)"
		
	estimates restore LEFT_base
	margins, at(cohort2=(0/4) East=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) ///  
		legend(off) title(PDS/LEFT) name(LEFT_base_coh, replace) nodraw
		
	estimates restore AfD_base
	margins, at(cohort3=(0/3) East=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) /// 
		legend(off) title(AfD) name(AfD_base_coh, replace) nodraw	
	
	* Combine figure for main parties with only cohort patterns
	graph combine UNION_base_coh SPD_base_coh FDP_base_coh GREENS_base_coh LEFT_base_coh /* AfD_base_coh */, row(3) imargin(tiny) ysize(6) iscale(*1.2) name(FigureD3, replace)	
	

	
	***** Figure D4: Predicted probability of party choice by cohorts and West vs. East (including abstention)
	* Regression models	
	* CDU/CSU
	logit votecducsu ib3.cohort##i.East i.year i.age_group i.sex [pweight=weightvoteshare_reg_wregionalw]
		estadd fitstat
		eststo UNION_base_wabst
		
	* SPD 
	logit votespd ib3.cohort##i.East i.year i.age_group i.sex [pweight=weightvoteshare_reg_wregionalw]
		estadd fitstat
		eststo SPD_base_wabst	
	
	* FDP
	logit votefdp ib3.cohort##i.East i.year i.age_group i.sex [pweight=weightvoteshare_reg_wregionalw]
		estadd fitstat
		eststo FDP_base_wabst
		
	* GREENS
	logit votegruene ib3.cohort2##i.East i.year i.age_group i.sex if year>=1980 [pweight=weightvoteshare_reg_wregionalw]
		estadd fitstat
		eststo GREENS_base_wabst	

	* PDS/LEFT
	logit votelinke ib3.cohort2##i.East i.year i.age_group i.sex if year>=1994 [pweight=weightvoteshare_reg_wregionalw]
		estadd fitstat
		eststo LEFT_base_wabst	

	* AfD
	logit voteafd ib3.cohort3##i.East i.year i.sex if year>=2013 [pweight=weightvoteshare_reg_wregionalw]
		estadd fitstat
		eststo AfD_base_wabst	
						 	
	* Predicted probabilities by cohort
	global ylabel "ylabel(.0 (.1) .4, gmin gmax)"
		
	estimates restore UNION_base_wabst
	margins, at(cohort=(0/5) East=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) ///  
		legend(off) text(0.18 2 "East", color(orange)) text(0.43 2 "West", color(ebblue)) title(CDU/CSU) name(UNION_base_coh_wabst, replace) nodraw
			
	estimates restore SPD_base_wabst
	margins, at(cohort=(0/5) East=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) ///  
		legend(off) title(SPD) name(SPD_base_coh_wabst, replace) nodraw
		
	global ylabel "ylabel(.0 (.05) .15, gmin gmax)"
		
	estimates restore FDP_base_wabst
	margins, at(cohort=(0/5) East=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) ///  
		legend(off) title(FDP) name(FDP_base_coh_wabst, replace) nodraw
			
	estimates restore GREENS_base_wabst
	margins, at(cohort2=(0/4) East=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) ///  
		legend(off) title(GREENS) name(GREENS_base_coh_wabst, replace) nodraw

	global ylabel "ylabel(.0 (.05) .2, gmin gmax)"

	estimates restore LEFT_base_wabst
	margins, at(cohort2=(0/4) East=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) ///  
		legend(off) title(PDS/LEFT) name(LEFT_base_coh_wabst, replace) nodraw
		
	estimates restore AfD_base_wabst
	margins, at(cohort3=(0/3) East=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) /// 
		legend(off) title(AfD) name(AfD_base_coh_wabst, replace) nodraw	
	
	* Combine figure for main parties with only cohort patterns
	graph combine UNION_base_coh_wabst SPD_base_coh_wabst FDP_base_coh_wabst GREENS_base_coh_wabst LEFT_base_coh_wabst AfD_base_coh_wabst, row(3) imargin(tiny) xsize(4) iscale(*1.2) name(FigureD4, replace)	

	
	
**# Bookmark #4		
***************************************************************************************************************************
*************************** APC MODELS WITH INTERACTIONS WITH EDUCATION: FOR WESTERN GERMANY ******************************
***************************************************************************************************************************	
	
	* Regression models	
	* CDU/CSU
	logit votecducsu ib3.cohort##i.educ_high i.year##i.educ_high i.age_group##i.educ_high i.sex if turnout==1 & East==0 [pweight=weight_voteshare_reg]
		estadd fitstat
		eststo UNION_edu
		
	* SPD 
	logit votespd ib3.cohort##i.educ_high i.year##i.educ_high i.age_group##i.educ_high i.sex if turnout==1 & East==0 [pweight=weight_voteshare_reg]
		estadd fitstat
		eststo SPD_edu
	
	* FDP
	logit votefdp ib3.cohort##i.educ_high i.year##i.educ_high i.age_group##i.educ_high i.sex if turnout==1 & East==0 [pweight=weight_voteshare_reg]
		estadd fitstat
		eststo FDP_edu
	
	* GREENS
	logit votegruene ib2.cohort2##i.educ_high i.year##i.educ_high i.age_group##i.educ_high i.sex if year>=1980 & turnout==1 & East==0 [pweight=weight_voteshare_reg]
		estadd fitstat
		eststo GREENS_edu		
	
	* PDS/LEFT
	logit votelinke ib1.cohort3##i.educ_high i.year##i.educ_high i.age_group##i.educ_high i.sex if year>=1994 & turnout==1 & East==0 [pweight=weight_voteshare_reg]
		estadd fitstat
		eststo LEFT_edu	
		
	* AfD
	logit voteafd ib1.cohort3##i.educ_high i.year##i.educ_high i.sex if year>=2013 & turnout==1 & East==0 [pweight=weight_voteshare_reg]
		estadd fitstat
		eststo AfD_edu	
	
		
	* Figure 3: Predicted probability of party choice by cohorts and high education in Western Germany 
	global ylabel "ylabel(.0 (.1) .6, gmin gmax)"
		
	estimates restore UNION_edu
	margins, at(cohort=(0/5) educ_high=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) ///  
		text(0.35 1.2 "lower education", color(ebblue)) text(0.65 2 "high education", color(orange)) ///	
		legend(off) title(CDU/CSU) name(UNION_edu_coh, replace) nodraw		
			
	estimates restore SPD_edu
	margins, at(cohort=(0/5) educ_high=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) ///  
		legend(off) title(SPD) name(SPD_edu_coh, replace) nodraw
		
	global ylabel "ylabel(.0 (.05) .25, gmin gmax)"
		
	estimates restore FDP_edu
	margins, at(cohort=(0/5) educ_high=(0 1)) post
		test _b[11._at] = _b[12._at]
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) ///  
		legend(off) title(FDP) name(FDP_edu_coh, replace) nodraw
			
	estimates restore GREENS_edu
	margins, at(cohort2=(0/4) educ_high=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) ///  
		legend(off) title(Greens) name(GREENS_edu_coh, replace) nodraw

	global ylabel "ylabel(.0 (.05) .2, gmin gmax)"

	estimates restore LEFT_edu
	margins, at(cohort3=(0/3) educ_high=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) ///  
		legend(off) title(PDS/LEFT) name(LEFT_edu_coh, replace) nodraw
		
	estimates restore AfD_edu
	margins, at(cohort3=(0/3) educ_high=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) /// 
		legend(off) title(AfD) name(AfD_edu_coh, replace) nodraw	
	
	* Combine to Figure 3 
	graph combine UNION_edu_coh SPD_edu_coh FDP_edu_coh GREENS_edu_coh LEFT_edu_coh AfD_edu_coh, row(3) imargin(tiny) xsize(4) iscale(*1.2) name(Figure3, replace)			
		graph export "Figure3.pdf", replace
		
		
	*** Appendix E: Further results for Figure 3 (APC model with education interaction for Western Germany)
		
	* Table E1: Regression table for results in Figure 3 (APC model with education interaction for Western Germany)
	esttab UNION_edu SPD_edu FDP_edu GREENS_edu LEFT_edu AfD_edu using "TableE1.rtf", b(a2) se(a2) star(+ 0.10 * 0.05 ** 0.01 *** 0.001) scalars(r2_mz) ///
		label nogaps ///
		drop(0.educ_high 0.cohort#0.educ_high 1.cohort#0.educ_high 2.cohort#0.educ_high 3.cohort#0.educ_high 4.cohort#0.educ_high ///
		1949.year 1949.year#0.educ_high 1949.year#1.educ_high 1953.year#0.educ_high 1957.year#0.educ_high 1961.year#0.educ_high 1965.year#0.educ_high 1969.year#0.educ_high ///
		1972.year#0.educ_high 1976.year#0.educ_high 1980.year#0.educ_high 1983.year#0.educ_high 1987.year#0.educ_high 1990.year#0.educ_high 1994.year#0.educ_high 1998.year#0.educ_high ///
		2002.year#0.educ_high 2005.year#0.educ_high 2009.year#0.educ_high 2013.year#0.educ_high 2017.year#0.educ_high 2021.year#0.educ_high ///
		0.age_group 0.age_group#0.educ_high 0.age_group#1.educ_high 1.age_group#0.educ_high 2.age_group#0.educ_high ///
		0.sex ///
		0.cohort2#0.educ_high 1.cohort2#0.educ_high 2.cohort2#0.educ_high 3.cohort2#0.educ_high) ///
		replace		
		
		
		* Figure E1: Predicted probabilities by cohort, age and election year from regression in Table E1
		global ylabel "ylabel(.0 (.1) .6, gmin gmax)"
		label values year year
	
		* CDU/CSU
		estimates restore UNION_edu
		
			* cohort effect
			margins, at(cohort=(0/5) educ_high=(0 1))
			mplotoffset, level(85) ytitle(" ") ///  
				text(0.22 2 "lower education", color(ebblue)) text(0.70 2 "high education", color(orange)) ///	
				xlabel( , angle(045)) ///
				legend(off) title(" ", size(zero)) name(UNION_edu_coh, replace) nodraw			

			* age effect
			margins, at(age_group=(0/3) educ_high=(0 1))
			mplotoffset, level(85) ytitle(" ") title(" ", size(zero)) /// 
				xlabel( , angle(045)) ///
				legend(off) name(UNION_edu_age, replace) nodraw	

			* period effect
			margins, at(year=(1949 1953 1957 1961 1965 1969 1972 1976 1980 1983 1987 1990 1994 1998 2002 2005 2009 2013 2017 2021) educ_high=(0 1))
			mplotoffset, level(85) ytitle(" ") title(" ", size(zero)) scale(*0.9) ///
				legend(off) name(UNION_edu_year, replace) nodraw

			* combine graphs
			graph combine UNION_edu_coh UNION_edu_age, row(1) imargin(zero) iscale(*1.2) name(UNION_edu_all, replace) nodraw

			graph combine UNION_edu_all UNION_edu_year, row(2) title(CDU/CSU, size(small)) imargin(zero) name(UNION_edu_all, replace) nodraw

		* SPD 
		estimates restore SPD_edu
		
			* cohort effect
			margins, at(cohort=(0/5) educ_high=(0 1))
			mplotoffset, level(85) ytitle(" ") $ylabel ///  
				xlabel( , angle(045)) ///
				legend(off) title(" ", size(zero)) name(SPD_edu_coh, replace) nodraw
		
			* age effect
			margins, at(age_group=(0/3) educ_high=(0 1))
			mplotoffset, level(85) ytitle(" ") title(" ", size(zero)) ///  
				xlabel( , angle(045)) ///
				legend(off) name(SPD_edu_age, replace) nodraw

			* period effect
			margins, at(year=(1949 1953 1957 1961 1965 1969 1972 1976 1980 1983 1987 1990 1994 1998 2002 2005 2009 2013 2017 2021) educ_high=(0 1))
			mplotoffset, level(85) ytitle(" ") title(" ", size(zero)) ylabel(.2 (.1) .5) scale(*0.9) $ylabel ///
				legend(off) name(SPD_edu_year, replace) nodraw

			* combine graphs
			graph combine SPD_edu_coh SPD_edu_age, row(1) imargin(zero) ycommon iscale(*1.2) name(SPD_edu_all, replace) nodraw

			graph combine SPD_edu_all SPD_edu_year, row(2) title(SPD, size(small)) imargin(zero) ycommon name(SPD_edu_all, replace) nodraw
					
		global ylabel "ylabel(.0 (.1) .3, gmin gmax)"
	
		* FDP
		estimates restore FDP_edu

			* cohort effect
			margins, at(cohort=(0/5) educ_high=(0 1))
			mplotoffset, level(85) ytitle(" ") title(" ", size(zero)) ///  
				xlabel( , angle(045)) ///
				legend(off) name(FDP_edu_coh, replace) nodraw

			* age effect
			margins, at(age_group=(0/3) educ_high=(0 1))
			mplotoffset, level(85) ytitle(" ") title(" ", size(zero)) ///  
				xlabel( , angle(045)) ///
				legend(off) name(FDP_edu_age, replace) nodraw

			* period effect
			margins, at(year=(1949 1953 1957 1961 1965 1969 1972 1976 1980 1983 1987 1990 1994 1998 2002 2005 2009 2013 2017 2021) educ_high=(0 1))
			mplotoffset, level(85) ytitle(" ") title(" ", size(zero)) scale(*0.9) $ylabel ///  
				legend(off) name(FDP_edu_year, replace) nodraw

			* combine graphs
			graph combine FDP_edu_coh FDP_edu_age, row(1) imargin(zero) ycommon iscale(*1.2) name(FDP_edu_all, replace) nodraw

			graph combine FDP_edu_all FDP_edu_year, row(2) title(FDP, size(small)) imargin(zero) ycommon name(FDP_edu_all, replace) nodraw 						
			
		* GREENS
		estimates restore GREENS_edu


			* cohort effect
			margins, at(cohort2=(0/4) educ_high=(0 1))
			mplotoffset, level(85) ytitle(" ") title(" ", size(zero)) ///  
				xlabel( , angle(045)) ///
				legend(off) name(GREENS_edu_coh, replace) nodraw

			* age effect
			margins, at(age_group=(0/3) educ_high=(0 1))
			mplotoffset, level(85) ytitle(" ") title(" ", size(zero)) ///  
				xlabel( , angle(045)) ///
				legend(off) name(GREENS_edu_age, replace) nodraw

			* period effect
			margins, at(year=(1980 1983 1987 1990 1994 1998 2002 2005 2009 2013 2017 2021) educ_high=(0 1))
			mplotoffset, level(85) ytitle(" ") title(" ", size(zero)) scale(*0.9) ///  
				legend(off) name(GREENS_edu_year, replace) nodraw

			* combine graphs
			graph combine GREENS_edu_coh GREENS_edu_age, row(1) imargin(zero) ycommon iscale(*1.2) name(GREENS_edu_all, replace) nodraw

			graph combine GREENS_edu_all GREENS_edu_year, row(2) title(Greens, size(small)) imargin(zero) ycommon name(GREENS_edu_all, replace) nodraw

			
		global ylabel "ylabel(.0 (.05) .2, gmin gmax)"
						
		* LINKE
		estimates restore LEFT_edu

			* cohort effect
			margins, at(cohort3=(0/3) educ_high=(0 1))
			mplotoffset, level(85) ytitle(" ") title(" ", size(zero)) ///  
				xlabel( , angle(045)) ///
				legend(off) name(LEFT_edu_coh, replace) nodraw

			* age effect
			margins, at(age_group=(0/3) educ_high=(0 1))
			mplotoffset, level(85) ytitle(" ") title(" ", size(zero)) ///  
				xlabel( , angle(045)) ///
				legend(off) name(LEFT_edu_age, replace) nodraw

			* period effect
			margins, at(year=(1994 1998 2002 2005 2009 2013 2017 2021) educ_high=(0 1))
			mplotoffset, level(85) ytitle(" ") title(" ", size(zero)) scale(*0.9) ///  
				legend(off) name(LEFT_edu_year, replace) nodraw

			* combine graphs
			graph combine LEFT_edu_coh LEFT_edu_age, row(1) imargin(zero) ycommon iscale(*1.2) name(LEFT_edu_all, replace) nodraw

			graph combine LEFT_edu_all LEFT_edu_year, row(2) title(PDS/LEFT, size(small)) imargin(zero) ycommon name(LEFT_edu_all, replace) nodraw
			
		* AfD (omit age group)
		estimates restore AfD_edu

			* cohort effect
			margins, at(cohort3=(0/3) educ_high=(0 1))
			mplotoffset, level(85) ytitle(" ") title(" ", size(zero)) /// 
				legend(off) scale(*0.9) name(AfD_edu_coh, replace) nodraw
			
			* period effect
			margins, at(year=(2013 2017 2021) educ_high=(0 1))
			mplotoffset, level(85) ytitle(" ") title(" ", size(zero)) scale(*0.9) ///  
				legend(off) name(AfD_edu_year, replace) nodraw

			* combine graphs
			graph combine AfD_edu_coh AfD_edu_year, row(2) title(AfD, size(small)) imargin(zero) ycommon name(AfD_edu_all, replace) nodraw
			
		*** Combine graph for main parties with cohort, period and age patterns
			graph combine UNION_edu_all SPD_edu_all FDP_edu_all GREENS_edu_all LEFT_edu_all AfD_edu_all, row(2) imargin(tiny) xsize(7.5) iscale(*1.4) name(FigureE1, replace)

			
			
**# Bookmark #5	
***************************************************************************************************************************
*** Appendix F: Results from robustness checks for Figure 3 (APC model with education interaction for Western Germany) ****
***************************************************************************************************************************

	***** Figure F1: Predicted probability of party choice by cohorts and high education (without weight)
	* Regression models	
	* CDU/CSU
	logit votecducsu ib3.cohort##i.educ_high i.year##i.educ_high i.age_group##i.educ_high i.sex if turnout==1 & East==0
		estadd fitstat
		eststo UNION_edu
		
	* SPD 
	logit votespd ib3.cohort##i.educ_high i.year##i.educ_high i.age_group##i.educ_high i.sex if turnout==1 & East==0
		estadd fitstat
		eststo SPD_edu
	
	* FDP
	logit votefdp ib3.cohort##i.educ_high i.year##i.educ_high i.age_group##i.educ_high i.sex if turnout==1 & East==0
		estadd fitstat
		eststo FDP_edu
	
	* GREENS
	logit votegruene ib2.cohort2##i.educ_high i.year##i.educ_high i.age_group##i.educ_high i.sex if year>=1980 & turnout==1 & East==0
		estadd fitstat
		eststo GREENS_edu		
	
	* PDS/LEFT
	logit votelinke ib1.cohort3##i.educ_high i.year##i.educ_high i.age_group##i.educ_high i.sex if year>=1994 & turnout==1 & East==0
		estadd fitstat
		eststo LEFT_edu	
		
	* AfD
	logit voteafd ib1.cohort3##i.educ_high i.year##i.educ_high i.sex if year>=2013 & turnout==1 & East==0
		estadd fitstat
		eststo AfD_edu	
		
	* Predicted probabilities by cohort
	global ylabel "ylabel(.0 (.1) .6, gmin gmax)"
		
	estimates restore UNION_edu
	margins, at(cohort=(0/5) educ_high=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) ///  
		text(0.35 1.2 "lower education", color(ebblue)) text(0.65 2 "high education", color(orange)) ///	
		legend(off) title(CDU/CSU) name(UNION_edu_coh, replace) nodraw
		
	estimates restore SPD_edu
	margins, at(cohort=(0/5) educ_high=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) ///  
		legend(off) title(SPD) name(SPD_edu_coh, replace) nodraw
		
	global ylabel "ylabel(.0 (.05) .3, gmin gmax)"
		
	estimates restore FDP_edu
	margins, at(cohort=(0/5) educ_high=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) ///  
		legend(off) title(FDP) name(FDP_edu_coh, replace) nodraw
			
	estimates restore GREENS_edu
	margins, at(cohort2=(0/4) educ_high=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) ///  
		legend(off) title(GREENS) name(GREENS_edu_coh, replace) nodraw

	global ylabel "ylabel(.0 (.05) .15, gmin gmax)"

	estimates restore LEFT_edu
	margins, at(cohort3=(0/3) educ_high=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) ///  
		legend(off) title(PDS/LEFT) name(LEFT_edu_coh, replace) nodraw
		
	estimates restore AfD_edu
	margins, at(cohort3=(0/3) educ_high=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) /// 
		legend(off) title(AfD) name(AfD_edu_coh, replace) nodraw	
	
	* Combine graph for main parties with only cohort patterns
	graph combine UNION_edu_coh SPD_edu_coh FDP_edu_coh GREENS_edu_coh LEFT_edu_coh AfD_edu_coh, row(3) imargin(tiny) ysize(6) iscale(*1.2) name(FigureF1, replace)		
	
	
	
	***** Figure F2: Predicted probability of party choice by cohorts and high education in Western Germany (fine-grained cohorts)	
	* Regression models	
	* CDU/CSU
	logit votecducsu ib3.cohort_dec##i.educ_high i.year##i.educ_high i.age_group##i.educ_high i.sex if turnout==1 & East==0 [pweight=weight_voteshare_reg]
		estadd fitstat
		eststo UNION_edu_finecoh
		
	* SPD 
	logit votespd ib3.cohort_dec##i.educ_high i.year##i.educ_high i.age_group##i.educ_high i.sex if turnout==1 & East==0 [pweight=weight_voteshare_reg]
		estadd fitstat
		eststo SPD_edu_finecoh
	
	* FDP
	logit votefdp ib3.cohort_dec##i.educ_high i.year##i.educ_high i.age_group##i.educ_high i.sex if turnout==1 & East==0 [pweight=weight_voteshare_reg]
		estadd fitstat
		eststo FDP_edu_finecoh
	
	* GREENS
	logit votegruene ib2.cohort_dec##i.educ_high i.year##i.educ_high i.age_group##i.educ_high i.sex if year>=1980 & turnout==1 & East==0 [pweight=weight_voteshare_reg]
		estadd fitstat
		eststo GREENS_edu_finecoh		
	
	* PDS/LEFT
	logit votelinke ib1.cohort_dec##i.educ_high i.year##i.educ_high i.age_group##i.educ_high i.sex if year>=1994 & turnout==1 & East==0 [pweight=weight_voteshare_reg]
		estadd fitstat
		eststo LEFT_edu_finecoh
		
	* AfD
	logit voteafd ib1.cohort_dec##i.educ_high i.year##i.educ_high i.sex if year>=2013 & turnout==1 & East==0 [pweight=weight_voteshare_reg]
		estadd fitstat
		eststo AfD_edu_finecoh	
		
		
	* Predicted probabilities by cohort
	global ylabel "ylabel(.0 (.1) .6, gmin gmax)"
		
	estimates restore UNION_edu_finecoh
	margins, at(cohort_dec=(0/8) educ_high=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) xlabel( , angle(90)) ///  
		text(0.22 4 "lower education", color(ebblue)) text(0.55 4 "high education", color(orange)) ///	
		legend(off) title(CDU/CSU) name(UNION_edu_finecoh, replace) nodraw
			
	estimates restore SPD_edu_finecoh
	margins, at(cohort_dec=(0/8) educ_high=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) xlabel( , angle(90)) ///  
		legend(off) title(SPD) name(SPD_edu_finecoh, replace) nodraw
		
	global ylabel "ylabel(.0 (.05) .35, gmin gmax)"
		
	estimates restore FDP_edu_finecoh
	margins, at(cohort_dec=(0/8) educ_high=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) xlabel( , angle(90)) ///  
		legend(off) title(FDP) name(FDP_edu_finecoh, replace) nodraw
			
	estimates restore GREENS_edu_finecoh
	margins, at(cohort_dec=(0/8) educ_high=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) xlabel( , angle(90)) ///  
		legend(off) title(GREENS) name(GREENS_edu_finecoh, replace) nodraw

	global ylabel "ylabel(.0 (.05) .25, gmin gmax)"

	estimates restore LEFT_edu_finecoh
	margins, at(cohort_dec=(0/8) educ_high=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) xlabel( , angle(90)) ///  
		legend(off) title(PDS/LEFT) name(LEFT_edu_finecoh, replace) nodraw
		
	estimates restore AfD_edu_finecoh
	margins, at(cohort_dec=(0/8) educ_high=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) xlabel( , angle(90)) /// 
		legend(off) title(AfD) name(AfD_edu_finecoh, replace) nodraw	
	
	* Combine graph for main parties with only cohort patterns
	graph combine UNION_edu_finecoh SPD_edu_finecoh FDP_edu_finecoh GREENS_edu_finecoh LEFT_edu_finecoh AfD_edu_finecoh, row(3) imargin(tiny) ysize(6) iscale(*1.2) name(FigureF2, replace)	
	
	
	
	***** Figure F3: Predicted probability of party choice by cohorts and high education in Western Germany (fine-grained age groups)
	* Regression models	
	* CDU/CSU
	logit votecducsu ib3.cohort##i.educ_high i.year##i.educ_high i.age_group2##i.educ_high i.sex if turnout==1 & East==0 [pweight=weight_voteshare_reg]
		estadd fitstat
		eststo UNION_edu
		
	* SPD 
	logit votespd ib3.cohort##i.educ_high i.year##i.educ_high i.age_group2##i.educ_high i.sex if turnout==1 & East==0 [pweight=weight_voteshare_reg]
		estadd fitstat
		eststo SPD_edu
	
	* FDP
	logit votefdp ib3.cohort##i.educ_high i.year##i.educ_high i.age_group2##i.educ_high i.sex if turnout==1 & East==0 [pweight=weight_voteshare_reg]
		estadd fitstat
		eststo FDP_edu
	
	* GREENS
	logit votegruene ib2.cohort2##i.educ_high i.year##i.educ_high i.age_group2##i.educ_high i.sex if year>=1980 & turnout==1 & East==0 [pweight=weight_voteshare_reg]
		estadd fitstat
		eststo GREENS_edu		
	
	* PDS/LEFT
	logit votelinke ib1.cohort3##i.educ_high i.year##i.educ_high i.age_group2##i.educ_high i.sex if year>=1994 & turnout==1 & East==0 [pweight=weight_voteshare_reg]
		estadd fitstat
		eststo LEFT_edu	
		
	* AfD
	logit voteafd ib1.cohort3##i.educ_high i.year##i.educ_high i.sex if year>=2013 & turnout==1 & East==0 [pweight=weight_voteshare_reg]
		estadd fitstat
		eststo AfD_edu	
		
	* Predicted probabilities by cohort
	global ylabel "ylabel(.0 (.1) .6, gmin gmax)"
		
	estimates restore UNION_edu
	margins, at(cohort=(0/5) educ_high=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) ///  
		text(0.35 1.2 "lower education", color(ebblue)) text(0.65 2 "high education", color(orange)) ///	
		legend(off) title(CDU/CSU) name(UNION_edu_coh, replace) nodraw
			
	estimates restore SPD_edu
	margins, at(cohort=(0/5) educ_high=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) ///  
		legend(off) title(SPD) name(SPD_edu_coh, replace) nodraw
		
	global ylabel "ylabel(.0 (.05) .25, gmin gmax)"
		
	estimates restore FDP_edu
	margins, at(cohort=(0/5) educ_high=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) ///  
		legend(off) title(FDP) name(FDP_edu_coh, replace) nodraw
			
	estimates restore GREENS_edu
	margins, at(cohort2=(0/4) educ_high=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) ///  
		legend(off) title(GREENS) name(GREENS_edu_coh, replace) nodraw

	global ylabel "ylabel(.0 (.05) .2, gmin gmax)"

	estimates restore LEFT_edu
	margins, at(cohort3=(0/3) educ_high=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) ///  
		legend(off) title(PDS/LEFT) name(LEFT_edu_coh, replace) nodraw
		
	estimates restore AfD_edu
	margins, at(cohort3=(0/3) educ_high=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) /// 
		legend(off) title(AfD) name(AfD_edu_coh, replace) nodraw	
	
	* Combine graph for main parties with only cohort patterns
	graph combine UNION_edu_coh SPD_edu_coh FDP_edu_coh GREENS_edu_coh LEFT_edu_coh /* AfD_edu_coh */, row(3) imargin(tiny) ysize(6) iscale(*1.2) name(FigureF3, replace)	
	
	
	
	***** Figure F4: Predicted probability of party choice by cohorts and high education in Western Germany (including abstention)
	* Regression models	
	* CDU/CSU
	logit votecducsu ib3.cohort##i.educ_high i.year##i.educ_high i.age_group##i.educ_high i.sex if East==0 [pweight=weight_voteshare_reg]
		estadd fitstat
		eststo UNION_edu_wabst
		
	* SPD 
	logit votespd ib3.cohort##i.educ_high i.year##i.educ_high i.age_group##i.educ_high i.sex if East==0 [pweight=weight_voteshare_reg]
		estadd fitstat
		eststo SPD_edu_wabst
	
	* FDP
	logit votefdp ib3.cohort##i.educ_high i.year##i.educ_high i.age_group##i.educ_high i.sex if East==0 [pweight=weight_voteshare_reg]
		estadd fitstat
		eststo FDP_edu_wabst
	
	* GREENS
	logit votegruene ib2.cohort2##i.educ_high i.year##i.educ_high i.age_group##i.educ_high i.sex if year>=1980 & East==0 [pweight=weight_voteshare_reg]
		estadd fitstat
		eststo GREENS_edu_wabst		
	
	* PDS/LEFT
	logit votelinke ib1.cohort3##i.educ_high i.year##i.educ_high i.age_group##i.educ_high i.sex if year>=1994 & East==0 [pweight=weight_voteshare_reg]
		estadd fitstat
		eststo LEFT_edu_wabst	
		
	* AfD
	logit voteafd ib1.cohort3##i.educ_high i.year##i.educ_high i.sex if year>=2013 & East==0 [pweight=weight_voteshare_reg]
		estadd fitstat
		eststo AfD_edu_wabst	
		
	* Predicted probabilities by cohort
	global ylabel "ylabel(.0 (.1) .6, gmin gmax)"
		
	estimates restore UNION_edu_wabst
	margins, at(cohort=(0/5) educ_high=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) ///  
		text(0.28 1.2 "lower education", color(ebblue)) text(0.58 2 "high education", color(orange)) ///	
		legend(off) title(CDU/CSU) name(UNION_edu_coh_wabst, replace) nodraw

	global ylabel "ylabel(.0 (.1) .4, gmin gmax)"
		
	estimates restore SPD_edu_wabst
	margins, at(cohort=(0/5) educ_high=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) ///  
		legend(off) title(SPD) name(SPD_edu_coh_wabst, replace) nodraw
		
	global ylabel "ylabel(.0 (.05) .25, gmin gmax)"
		
	estimates restore FDP_edu_wabst
	margins, at(cohort=(0/5) educ_high=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) ///  
		legend(off) title(FDP) name(FDP_edu_coh_wabst, replace) nodraw
			
	estimates restore GREENS_edu_wabst
	margins, at(cohort2=(0/4) educ_high=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) ///  
		legend(off) title(GREENS) name(GREENS_edu_coh_wabst, replace) nodraw

	global ylabel "ylabel(.0 (.05) .15, gmin gmax)"

	estimates restore LEFT_edu_wabst
	margins, at(cohort3=(0/3) educ_high=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) ///  
		legend(off) title(PDS/LEFT) name(LEFT_edu_coh_wabst, replace) nodraw
		
	estimates restore AfD_edu_wabst
	margins, at(cohort3=(0/3) educ_high=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) /// 
		legend(off) title(AfD) name(AfD_edu_coh_wabst, replace)	nodraw
	
	* Combine graph for main parties with only cohort patterns
	graph combine UNION_edu_coh_wabst SPD_edu_coh_wabst FDP_edu_coh_wabst GREENS_edu_coh_wabst LEFT_edu_coh_wabst AfD_edu_coh_wabst, row(3) imargin(tiny) ysize(6) iscale(*1.2) name(FigureF4, replace)		


			
**# Bookmark #6	
***************************************************************************************************************************
*************************************** Appendix G: Results for voter turnout *********************************************
***************************************************************************************************************************
	
	* baseline regression model
	logit turnout ib3.cohort##i.East i.year i.age_group i.sex [pweight=weightvoteshare_reg_wregionalw]
		estadd fitstat
		eststo turnout_base
		
	* model with education interaction (WEST)
	capture clonevar year2=year
	logit turnout ib3.cohort##i.educ_high i.year c.year2##i.educ_high i.age_group##i.educ_high i.sex if East==0 [pweight=weight_voteshare_reg]	
		estadd fitstat
		eststo turnout_edu_West
		
		* Table G1: Regression table for voter turnout 
		esttab turnout_base turnout_edu_West using "TableG1.rtf", b(a2) se(a2) star(* 0.05 ** 0.01 *** 0.001) scalars(r2_mz) ///
			label nogaps  ///
			drop(0.East 0.age_group 0.sex 0.cohort#0.East 1.cohort#0.East 2.cohort#0.East 3.cohort#0.East 4.cohort#0.East ///
			1949.year 0.educ_high 0.cohort#0.educ_high 1.cohort#0.educ_high 2.cohort#0.educ_high 3.cohort#0.educ_high 4.cohort#0.educ_high ///
			0.age_group#0.educ_high 0.age_group#1.educ_high 1.age_group#0.educ_high 2.age_group#0.educ_high year2 0.educ_high#c.year2) ///
			replace
	
	
	* Figure G1: Predicted probability of turning to vote across cohorts and East vs. West (from model in Table G1)/education (from model 2 in Table G1) 
	global ylabel "ylabel(.5 (.1) 1, gmin gmax)"
	
	* baseline
	estimates restore turnout_base
	margins, at(cohort=(0/5) East=(0 1))
		mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) $ylabel ///  
			legend(off) text(0.72 2 "East", color(orange)) text(0.91 2 "West", color(ebblue)) ///
			title(by cohort and West vs. East, size(medium)) name(turnout_base_coh, replace) nodraw
	
	* by education---West
	estimates restore turnout_edu_West
	margins, at(cohort=(0/5) educ_high=(0 1))
		mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) $ylabel ///  
			legend(off) text(0.75 2 "lower education", color(ebblue)) text(0.97 2 "high education", color(orange)) ///
			title(by cohort and education (West), size(medium)) name(turnout_edu_coh, replace) nodraw
	
		* combine graphs
		graph combine turnout_base_coh turnout_edu_coh, row(1) imargin(tiny) xsize(7) iscale(*1.6) name(FigureG1, replace)	

		
		
**# Bookmark #7	
***************************************************************************************************************************
*************************************** Appendix H: Results on the education divide for Eastern Germany *******************
***************************************************************************************************************************

	* Regression models	
	* CDU/CSU
	logit votecducsu ib1.cohort3##i.educ_high i.year##i.educ_high i.age_group##i.educ_high i.sex if turnout==1 & East==1 [pweight=weight_voteshare_reg]
		estadd fitstat
		eststo UNION_edu_East
		
	* SPD 
	logit votespd ib1.cohort3##i.educ_high i.year##i.educ_high i.age_group##i.educ_high i.sex if turnout==1 & East==1 [pweight=weight_voteshare_reg]
		estadd fitstat
		eststo SPD_edu_East
	
	* FDP
	logit votefdp ib1.cohort3##i.educ_high i.year##i.educ_high i.age_group##i.educ_high i.sex if turnout==1 & East==1 [pweight=weight_voteshare_reg]
		estadd fitstat
		eststo FDP_edu_East
	
	* GREENS
	logit votegruene ib1.cohort3##i.educ_high i.year##i.educ_high i.age_group##i.educ_high i.sex if year>=1980 & turnout==1 & East==1 [pweight=weight_voteshare_reg]
		estadd fitstat
		eststo GREENS_edu_East		
	
	* PDS/LEFT
	logit votelinke ib1.cohort3##i.educ_high i.year##i.educ_high i.age_group##i.educ_high i.sex if year>=1994 & turnout==1 & East==1 [pweight=weight_voteshare_reg]
		estadd fitstat
		eststo LEFT_edu_East	
		
	* AfD
	logit voteafd ib1.cohort3##i.educ_high i.year##i.educ_high i.sex if year>=2013 & turnout==1 & East==1 [pweight=weight_voteshare_reg]
		estadd fitstat
		eststo AfD_edu_East	
	
		
	* Figure 4: Predicted probability of party choice by cohorts and high education in Eastern Germany  
	global ylabel "ylabel(.0 (.1) .4, gmin gmax)"
		
	estimates restore UNION_edu_East	
	margins, at(cohort3=(0/3) educ_high=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) ///  
		text(0.36 1.5 "lower education", color(ebblue)) text(0.19 1.5 "high education", color(orange)) ///	
		legend(off) title(CDU/CSU) name(UNION_edu_coh_East, replace) nodraw
			
	estimates restore SPD_edu_East	
	margins, at(cohort3=(0/3) educ_high=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) ///  
		legend(off) title(SPD) name(SPD_edu_coh_East, replace) nodraw
		
	global ylabel "ylabel(.0 (.025) .1, gmin gmax)"
		
	estimates restore FDP_edu_East	
	margins, at(cohort3=(0/3) educ_high=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) ///  
		legend(off) title(FDP) name(FDP_edu_coh_East, replace) nodraw
	
	global ylabel "ylabel(.0 (.05) .25, gmin gmax)"
			
	estimates restore GREENS_edu_East	
	margins, at(cohort3=(0/3) educ_high=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) ///  
		legend(off) title(GREENS) name(GREENS_edu_coh_East, replace) nodraw

	global ylabel "ylabel(.0 (.05) .35, gmin gmax)"

	estimates restore LEFT_edu_East	
	margins, at(cohort3=(0/3) educ_high=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) ///  
		legend(off) title(PDS/LEFT) name(LEFT_edu_coh_East, replace) nodraw
		
	estimates restore AfD_edu_East	
	margins, at(cohort3=(0/3) educ_high=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) /// 
		legend(off) title(AfD) name(AfD_edu_coh_East, replace) nodraw 
	
	* Combine to Figure 4
	graph combine UNION_edu_coh_East SPD_edu_coh_East FDP_edu_coh_East GREENS_edu_coh_East LEFT_edu_coh_East AfD_edu_coh_East, row(3) imargin(tiny) ysize(6) iscale(*1.2) name(Figure4, replace)			
		graph export "Figure4.pdf", replace
		
		
	* Table H1: Regression table for results in Figure 4 (APC model with education interaction for Eastern Germany)
	esttab UNION_edu_East SPD_edu_East FDP_edu_East GREENS_edu_East LEFT_edu_East AfD_edu_East using "TableH1.rtf", b(a2) se(a2) star(+ 0.10 * 0.05 ** 0.01 *** 0.001) scalars(r2_mz) ///
		label nogaps ///
		drop(1.cohort3#0.educ_high 2.cohort3#0.educ_high 3.cohort3#0.educ_high ///
		1994.year#0.educ_high 1998.year#0.educ_high ///
		2002.year#0.educ_high 2005.year#0.educ_high 2009.year#0.educ_high 2013.year#0.educ_high 2017.year#0.educ_high 2021.year#0.educ_high ///
		0.age_group 0.age_group#0.educ_high 0.age_group#1.educ_high 1.age_group#0.educ_high 2.age_group#0.educ_high ///
		0.sex) ///
		replace
		

	***** Figure H1: Predicted probability of party choice by cohorts and high education in Eastern Germany (fine-grained cohorts)
	
	* Regression models	
	* CDU/CSU
	logit votecducsu ib1.cohort_dec2##i.educ_high i.year##i.educ_high i.age_group##i.educ_high i.sex if turnout==1 & East==1 [pweight=weight_voteshare_reg]
		estadd fitstat
		eststo UNION_edu_East_finecoh
		
	* SPD 
	logit votespd ib1.cohort_dec2##i.educ_high i.year##i.educ_high i.age_group##i.educ_high i.sex if turnout==1 & East==1 [pweight=weight_voteshare_reg]
		estadd fitstat
		eststo SPD_edu_East_finecoh
	
	* FDP
	logit votefdp ib1.cohort_dec2##i.educ_high i.year##i.educ_high i.age_group##i.educ_high i.sex if turnout==1 & East==1 [pweight=weight_voteshare_reg]
		estadd fitstat
		eststo FDP_edu_East_finecoh
	
	* GREENS
	logit votegruene ib1.cohort_dec2##i.educ_high i.year##i.educ_high i.age_group##i.educ_high i.sex if year>=1980 & turnout==1 & East==1 [pweight=weight_voteshare_reg]
		estadd fitstat
		eststo GREENS_edu_East_finecoh		
	
	* PDS/LEFT
	logit votelinke ib1.cohort_dec2##i.educ_high i.year##i.educ_high i.age_group##i.educ_high i.sex if year>=1994 & turnout==1 & East==1 [pweight=weight_voteshare_reg]
		estadd fitstat
		eststo LEFT_edu_East_finecoh	
		
	* AfD
	logit voteafd ib1.cohort_dec2##i.educ_high i.year##i.educ_high i.sex if year>=2013 & turnout==1 & East==1 [pweight=weight_voteshare_reg]
		estadd fitstat
		eststo AfD_edu_East_finecoh	
		
	
	* Predicted probabilities by cohort
	global ylabel "ylabel(.0 (.1) .4, gmin gmax)"
		
	estimates restore UNION_edu_East_finecoh	
	margins, at(cohort_dec2=(0/6) educ_high=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) xlabel( , angle(90)) ///  
		text(0.41 3 "lower education", color(ebblue)) text(0.17 3 "high education", color(orange)) ///	
		legend(off) title(CDU/CSU) name(UNION_edu_finecoh_East, replace) nodraw
			
	estimates restore SPD_edu_East_finecoh	
	margins, at(cohort_dec2=(0/6) educ_high=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) xlabel( , angle(90)) ///  
		legend(off) title(SPD) name(SPD_edu_finecoh_East, replace) nodraw
		
	global ylabel "ylabel(.0 (.05) .15, gmin gmax)"
		
	estimates restore FDP_edu_East_finecoh	
	margins, at(cohort_dec2=(0/6) educ_high=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) xlabel( , angle(90)) ///  
		legend(off) title(FDP) name(FDP_edu_finecoh_East, replace) nodraw
			
	global ylabel "ylabel(.0 (.1) .4, gmin gmax)"
			
	estimates restore GREENS_edu_East_finecoh	
	margins, at(cohort_dec2=(0/6) educ_high=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) xlabel( , angle(90)) ///  
		legend(off) title(GREENS) name(GREENS_edu_finecoh_East, replace) nodraw

	global ylabel "ylabel(.0 (.1) .4, gmin gmax)"

	estimates restore LEFT_edu_East_finecoh	
	margins, at(cohort_dec2=(0/6) educ_high=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) xlabel( , angle(90)) ///  
		legend(off) title(PDS/LEFT) name(LEFT_edu_finecoh_East, replace) nodraw
		
	estimates restore AfD_edu_East_finecoh	
	margins, at(cohort_dec2=(0/6) educ_high=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) xlabel( , angle(90)) /// 
		legend(off) title(AfD) name(AfD_edu_finecoh_East, replace) nodraw	
	
	* Combine graph for main parties with only cohort patterns
	graph combine UNION_edu_finecoh_East SPD_edu_finecoh_East FDP_edu_finecoh_East GREENS_edu_finecoh_East LEFT_edu_finecoh_East AfD_edu_finecoh_East, row(3) imargin(tiny) ysize(6) iscale(*1.2) name(FigureH1, replace)			
				
				
	
	***** Figure H2: Predicted probability of party choice by cohorts and high education in Eastern Germany (including abstention)
	
	* Regression models	
	* CDU/CSU
	logit votecducsu ib1.cohort3##i.educ_high i.year##i.educ_high i.age_group##i.educ_high i.sex if East==1 [pweight=weight_voteshare_reg]
		estadd fitstat
		eststo UNION_edu_East_wabst
		
	* SPD 
	logit votespd ib1.cohort3##i.educ_high i.year##i.educ_high i.age_group##i.educ_high i.sex if East==1 [pweight=weight_voteshare_reg]
		estadd fitstat
		eststo SPD_edu_East_wabst
	
	* FDP
	logit votefdp ib1.cohort3##i.educ_high i.year##i.educ_high i.age_group##i.educ_high i.sex if East==1 [pweight=weight_voteshare_reg]
		estadd fitstat
		eststo FDP_edu_East_wabst
	
	* GREENS
	logit votegruene ib1.cohort3##i.educ_high i.year##i.educ_high i.age_group##i.educ_high i.sex if year>=1980 & East==1 [pweight=weight_voteshare_reg]
		estadd fitstat
		eststo GREENS_edu_East_wabst		
	
	* PDS/LEFT
	logit votelinke ib1.cohort3##i.educ_high i.year##i.educ_high i.age_group##i.educ_high i.sex if year>=1994 & East==1 [pweight=weight_voteshare_reg]
		estadd fitstat
		eststo LEFT_edu_East_wabst	
		
	* AfD
	logit voteafd ib1.cohort3##i.educ_high i.year##i.educ_high i.sex if year>=2013 & East==1 [pweight=weight_voteshare_reg]
		estadd fitstat
		eststo AfD_edu_East_wabst	
	
	* Predicted probabilities by cohort
	global ylabel "ylabel(.0 (.1) .3, gmin gmax)"
		
	estimates restore UNION_edu_East_wabst	
	margins, at(cohort3=(0/3) educ_high=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) ///  
		text(0.15 1.5 "lower education", color(ebblue)) text(0.30 1.5 "high education", color(orange)) ///	
		legend(off) title(CDU/CSU) name(UNION_edu_coh_East_wabst, replace) nodraw
		
	estimates restore SPD_edu_East_wabst	
	margins, at(cohort3=(0/3) educ_high=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) ///  
		legend(off) title(SPD) name(SPD_edu_coh_East_wabst, replace) nodraw
		
	global ylabel "ylabel(.0 (.025) .1, gmin gmax)"
		
	estimates restore FDP_edu_East_wabst	
	margins, at(cohort3=(0/3) educ_high=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) ///  
		legend(off) title(FDP) name(FDP_edu_coh_East_wabst, replace) nodraw
	
	global ylabel "ylabel(.0 (.05) .25, gmin gmax)"
			
	estimates restore GREENS_edu_East_wabst	
	margins, at(cohort3=(0/3) educ_high=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) ///  
		legend(off) title(GREENS) name(GREENS_edu_coh_East_wabst, replace) nodraw

	global ylabel "ylabel(.0 (.05) .3, gmin gmax)"

	estimates restore LEFT_edu_East_wabst	
	margins, at(cohort3=(0/3) educ_high=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) ///  
		legend(off) title(PDS/LEFT) name(LEFT_edu_coh_East_wabst, replace) nodraw
		
	estimates restore AfD_edu_East_wabst	
	margins, at(cohort3=(0/3) educ_high=(0 1))
	mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) /// 
		legend(off) title(AfD) name(AfD_edu_coh_East_wabst, replace) nodraw 
	
	* Combine graph for main parties with only cohort patterns
	graph combine UNION_edu_coh_East_wabst SPD_edu_coh_East_wabst FDP_edu_coh_East_wabst GREENS_edu_coh_East_wabst LEFT_edu_coh_East_wabst AfD_edu_coh_East_wabst, row(3) imargin(tiny) ysize(6) iscale(*1.2) name(FigureH2, replace)			
				
		
		
	****** Figure H3: Predicted probability of voting across cohorts by education within Eastern Germany
	* model with education interaction---EAST
	logit turnout i.cohort2##i.educ_high i.year i.year##i.educ_high i.age_group##i.educ_high i.sex if East==1 [pweight=weight_voteshare_reg]	
		estadd fitstat
		eststo turnout_edu_East
		
		
	* model with education interaction---EAST, fine-grained cohorts
	logit turnout i.cohort_dec2##i.educ_high i.year i.year##i.educ_high i.age_group##i.educ_high i.sex if East==1 [pweight=weight_voteshare_reg]	
		estadd fitstat
		eststo turnout_edu_East_finecoh
		
	* Predicted probabilities by cohort
	global ylabel "ylabel(.0 (.1) 1, gmin gmax)"
	
	* by education
	estimates restore turnout_edu_East
	margins, at(cohort2=(0/4) educ_high=(0 1))
		mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) ///  
			legend(off) text(0.63 2 "lower education", color(ebblue)) text(0.97 2 "high education", color(orange)) ///
			title(main cohorts, size(medium)) name(turnout_edu_East_coh, replace) nodraw
	
	* by education
	estimates restore turnout_edu_East_finecoh
	margins, at(cohort_dec2=(0/6) educ_high=(0 1))
		mplotoffset, level(85) ytitle(" ", size(zero)) xtitle(" ", size(zero)) ///  
			legend(off) ///
			title(fine-grained cohorts, size(medium)) name(turnout_edu_East_finecoh, replace) nodraw
			
	* combine graphs
		graph combine turnout_edu_East_coh turnout_edu_East_finecoh, row(1) ycommon imargin(tiny) xsize(7) iscale(*1.5) name(FigureH3, replace)	